package structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * @author dali
 * @date 2021-07-20 18:29
 * @Description 共享对象工厂
 */

public class ChessFactory {
    private static final Map<String,Chess> chessMap = new HashMap<>();

    public static Chess getChess(String color) {
        Chess chess = chessMap.get(color);
        if (chess == null) {
            chess = "黑".equals(color) ? new BlackChess() : new WhiteChess();
            chessMap.put(color,chess);
        }
        return chess;
    }
}
